import { adhubRequest as request, fileServerRequest } from '@/utils/request';
import { stringify } from 'qs';

import type { SubmitType } from './Detail/components/EditBasicInfo';
import type { DatasetQueryParams } from './index';

export async function getDataType() {
  return await request(`/metadata/data-type`);
}

export async function getMetaData() {
  return await request(`/metadata/dataset`);
}

export async function getDetail(id: string) {
  return await request(`/datasets-collection/${id}`);
}

export async function getDataSet(params: DatasetQueryParams) {
  return await request(`/datasets?${stringify(params)}`);
}

export async function editDataSet(id: string, params: SubmitType) {
  return await request(`/datasets-collection/${id}`, {
    method: 'POST',
    data: params,
  });
}

export async function getAnnotInfo(id: string | number) {
  return await request(`/datasets/${id}/annots`);
}

export async function addUnstructuredDataSet(params: any) {
  return await request(`/datasets/unstructured-datasets`, {
    method: 'POST',
    data: params
  });
}

export const getVersionListAPI = (id: string | number) => {
  return `/datasets-collection/${id}/versions`;
}

export async function downloadDataSet(id: string | number) {
  return await request(`/datasets/${id}/download`, {
    method: 'POST',
  });
}

export async function releaseDataSet(id: string | number) {
  return await request(`/datasets/${id}/publish`, {
    method: 'POST',
  });
}

export async function deleteDataSet(id: string | number) {
  return await request(`/datasets/${id}`, {
    method: 'DELETE',
  });
}

export async function getFileDirectory(id: string | number, folder?: string) {
  return await request(`/datasets/${id}/file-directory${folder ? '?' + stringify({ folder }) : ''}`);
}

export async function getFile(id: string | number, path: string) {
  return await request(`/datasets/${id}/file-directory/file`, {
    method: 'GET',
    params: {
      path
    }
  });
}

export async function getFileInfo(id: string | number) {
  return await fileServerRequest(`/files/info/${id}`);
}